#include "ledarray.h"
#include <assert.h>


LedArray::LedArray(uchar num,QStringList &strlist,bool isvertical,QWidget *parent) :
    QWidget(parent),arraynumber(num),namelist(strlist)
{

    assert(num<33);
//#error arraynumber larger than 32

    char strlistsize=strlist.size();
    gridlayout=new QGridLayout;
    for(int i=0;i<num;i++)
   {
    ledvector<<new LedControl;
    labellist<<new QLabel;
    QString labeltext;
    if(strlistsize < i+1 ) labeltext=QString("%1").arg(i);
    else labeltext=strlist[i];
    labellist[i]->setText(labeltext);

    if(isvertical)
    {
    gridlayout->addWidget(labellist[i],i,0,1,1);
    gridlayout->addWidget(ledvector[i],i,1);
    }
    else
    {
       gridlayout->addWidget(ledvector[i],0,i);
       gridlayout->addWidget(labellist[i],1,i,1,2);
      // labellist[i]->setAlignment(Qt::AlignLeft);
       labellist[i]->setAlignment(Qt::AlignVertical_Mask |Qt::AlignTop);

    }
    ledvector[i]->show();
    }
    setLayout(gridlayout);


}

void LedArray::set_one_value(uchar num, bool onoroff)
{
    ledvector[num]->power(onoroff);
}
void LedArray::set_array_value(int value)
{
    bool b;
    for(int i=0;i<arraynumber;i++)
    {
       b=value & 0x0001<<i;
       if(b) ledvector[i]->power(true);
       else  ledvector[i]->power(false);
    }

}

